﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

using Microsoft.Forums.MicrosoftForumsProvider;
using Microsoft.Forums.SyncService;
using Microsoft.Forums.OfflineStore;
using LocalApp = Microsoft.Forums.ForumsClient;
using Microsoft.Forums.ForumsClient.Models;

namespace Microsoft.Forums.ForumsClient
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// Choose Dictionary with the view that we might want to show the theme names 
        /// somewhere on the GUI later,though only using it as a collection now.
        /// </summary>
        private Dictionary<string, ResourceDictionary> themes = new Dictionary<string, ResourceDictionary>();

        /// <summary>
        ///  Return the Themes which is a collection of ResourceDictionary
        /// </summary>
        public Dictionary<string, ResourceDictionary> Themes
        {
            get { return themes; }
        }


        /// <summary>
        ///  On App Startup
        /// </summary>
        /// <param name="sender">The object which raised this event</param>
        /// <param name="e">Startup Event Arguments</param>
        void App_Startup(object sender, StartupEventArgs e)
        {
            // Initialize View Resources
            var views = new ResourceDictionary();
            views.Source = new Uri("../Views/Views.xaml", UriKind.Relative);
            Application.Current.Resources.MergedDictionaries.Add(views);

            // Import or load all the theme files here.
            ImportThemes();
            AppDataModel.Initialize();

        }


        /// <summary>
        ///  Import or Load all the defined theme files here.
        ///  
        ///  Notes:
        ///      Themes are defined in individual xaml files and are placed under /themes folder.
        ///      Couple of points to remember
        ///      1. The theme xaml files are marked as content only and copy always.
        ///      2. Since they are content only you could modify the theme file without
        ///         need to recompile if you want any local customizations.
        ///      3. All theme files need to added as a project item even though they are only marked
        ///         as content only. What this means is that you cannot randomly put some theme file
        ///         and write code to pick it up in your app.
        /// </summary>
        private void ImportThemes()
        {
            ResourceDictionary blueTheme = (ResourceDictionary)Application.LoadComponent(new Uri("AppThemes;v1.0.0.0;Component/BlueTheme.xaml", UriKind.RelativeOrAbsolute));
            themes.Add("Blue", blueTheme);

            ResourceDictionary greenTheme = (ResourceDictionary)Application.LoadComponent(new Uri("AppThemes;v1.0.0.0;Component/GreenTheme.xaml", UriKind.RelativeOrAbsolute));
            themes.Add("Green", greenTheme);

            ResourceDictionary metalTheme = (ResourceDictionary)Application.LoadComponent(new Uri("AppThemes;v1.0.0.0;Component/MetalTheme.xaml", UriKind.RelativeOrAbsolute));
            themes.Add("Metal", metalTheme);
        }

        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);

            LocalApp.Properties.Settings.Default.Save();
        }
    }
}
